package put.poznan.qmese.matlab.control;

import put.poznan.qmese.matlab.model.CalculationException;
import put.poznan.qmese.matlab.model.Chunk;
import put.poznan.qmese.matlab.model.Matrix;
import put.poznan.qmese.matlab.model.Memory;
import put.poznan.qmese.matlab.model.Operation;
import put.poznan.qmese.matlab.parser.MatrixParser;
import put.poznan.qmese.matlab.parser.ParserException;


public class Control {

	private MatrixParser parser = new MatrixParser();
	
	/**
	 * Handles a single command
	 * @param command
	 * @throws ParserException 
	 */
	public void handle(String command) {
		
		try {
			Chunk chunk = parser.parse(command);
			
			if (chunk instanceof Operation){
				Matrix matrix = ((Operation)chunk).calculate();
				Memory.put(matrix.getId(), matrix);
			}
		} catch (ParserException e) {
			e.printStackTrace();
		} catch (CalculationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

	


	
	
}
